define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/taskrecords/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'jdy_taskrecords',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('詳情'),
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    icon: 'fa fa-dashboard',
                                    url: 'jdy/taskrecords/detail'
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        //{field: 'task_id', title: __('Task_id'), operate:false},
                        //{field: 'task.title', title: __('Task.title')},
                        {field: 'remind_type', title: __('Remind_type'), operate:false, searchList: {"不提醒":__('不提醒'),"一般件單日提醒":__('一般件單日提醒'),"一般件多日提醒":__('一般件多日提醒'),"急件":__('急件')}, formatter: Table.api.formatter.normal},
                        {field: 'remind_date', title: __('Remind_date'), operate:false},
                        {field: 'quotation_no', title: __('Quotation_no'), operate:false},
                        {field: 'work_no', title: __('Work_no'), operate:false},
                        {field: 'title', title: __('Title'), operate:false},
                        {field: 'task_status', title: __('Task_status'), operate:false, searchList: {"一般作業":__('一般作業'),"緊急搶修(先請後扣)":__('緊急搶修(先請後扣)'),"緊急搶修(請了不扣)":__('緊急搶修(請了不扣)'),"待報價":__('待報價'),"已報價":__('已報價'),"待簽認":__('待簽認'),"待備料":__('待備料'),"待施工":__('待施工'),"未完工":__('未完工'),"待請款":__('待請款'),"已出單":__('已出單'),"已收款":__('已收款'),"已結案":__('已結案')}, formatter: Table.api.formatter.status},
                        {field: 'maintenanceuser', title: __('Maintenanceuser_id'), operate:false},
                        {field: 'handleuser', title: __('Handleuser_id'), operate:false},
                        {field: 'notifyuser_ids', title: __('Notifyuser_ids'), operate:false},
                        {field: 'notify_msg', title: __('Notify_msg'), operate:false},
                        {field: 'luruman', title: __('Luruman'), operate:false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'task.id', title: __('Task.id')},
                        //{field: 'task.anchang_id', title: __('Task.anchang_id')},
                        //{field: 'task.remind_type', title: __('Task.remind_type')},
                        //{field: 'task.remind_date', title: __('Task.remind_date'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'task.replay', title: __('Task.replay')},
                        //{field: 'task.quotation_no', title: __('Task.quotation_no')},
                        //{field: 'task.work_no', title: __('Task.work_no')},
                        //{field: 'task.title', title: __('Task.title')},
                        //{field: 'task.task_status', title: __('Task.task_status'), formatter: Table.api.formatter.status},
                        //{field: 'task.maintenanceuser_id', title: __('Task.maintenanceuser_id')},
                        //{field: 'task.handleuser_id', title: __('Task.handleuser_id')},
                        //{field: 'task.notifyuser_ids', title: __('Task.notifyuser_ids')},
                        //{field: 'task.share_to_comm', title: __('Task.share_to_comm')},
                        //{field: 'task.notify_msg', title: __('Task.notify_msg')},
                        //{field: 'task.acdevice_ids', title: __('Task.acdevice_ids')},
                        //{field: 'task.baogu', title: __('Task.baogu')},
                        //{field: 'task.images', title: __('Task.images'), formatter: Table.api.formatter.images},
                        //{field: 'task.price', title: __('Task.price')},
                        //{field: 'task.luruman', title: __('Task.luruman')},
                        //{field: 'task.create_time', title: __('Task.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'task.update_time', title: __('Task.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});